package sctu.edu.java.year2016.team02.zhoujie.day20160522.chapter4_3;

/**
 * Created by ACER on 2016/5/23.
 */
/*编写java程序，利用while循环计算1+1/2!+1/3!……+1/20!的和*/
import java.math.BigDecimal;

public class sum {
    public static void main(String args[]) {
        BigDecimal sum = new BigDecimal(0.0);
         BigDecimal factorial = new BigDecimal(1.0);
          int i = 1;
            while (i <= 20) {
                sum = sum.add(factorial);
                         ++i;
                           factorial = factorial.multiply(new BigDecimal(1.0 / i));
                             }        System.out.println("1+1／2!+1／3!···1／20!=" + sum);   }}

